﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <link rel="StyleSheet" href="/css/cms/main.css?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/css/cms/main.css")) %>"  type="text/css" />
    <script src="/Scripts/common/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/common/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/Scripts/common/util.js" type="text/javascript"></script>
    <script src="/Scripts/common/form.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/common/form.js")) %>" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/cms/main.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/cms/main.js")) %>"></script>
    <script src="/Scripts/datepicker/js/jquery-ui-1.7.custom.min.js" type="text/javascript"></script>
    <link href="/Scripts/datepicker/css/smoothness/jquery-ui-1.7.custom.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/Scripts/swfupload/handlers.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/swfupload/handlers.js")) %>"></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.bgiframe.min.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.ajaxQueue.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/thickbox-compressed.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.autocomplete.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/autoseeklib/jquery.autocomplete.js")) %>'></script>
    <script type='text/javascript' src='/Scripts/cms/localdata.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/cms/localdata.js")) %>'></script>
	<link rel="stylesheet" type="text/css" href="/Scripts/autoseeklib/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="/Scripts/autoseeklib/thickbox.css" />
</head>
<script type="text/javascript" language="JavaScript">
    var role = { R_id: 0, R_Name: "", R_Desc: "", R_SectionCodeList: "", R_addTime: new Date() };
    var mylist;
    var regular_input = {
        R_Name: { exp: /^.{1,100}$/, m: "请输入角色名称，100个字符以内" }
    }
    var mainForm = "";
    $(document).ready(function () {
        //mainForm = $("#mainForm").html();
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        function ajax() {
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage };
            $.post("/system/getRolelist.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            var mapid;
            $("#mainTable tbody[name=mainlist]").html("");
            $.each(list, function (i, n) {
                sp.push('<tr>');
                sp.push('<td title=' + n.R_Desc + '>' + n.R_Name + '</td>'); //R_Desc
                sp.push('<td title=' + n.R_SectionCodeList + '>' + (n.R_SectionCodeList.length > 70 ? n.R_SectionCodeList.substring(0, 70) + '...' : n.R_SectionCodeList) + '</td>');
                sp.push('<td><a href="#mainForm" onclick="edit(' + n.R_id + ')" name="linkEdit" vid="' + n.R_id + '">修改</a>  <a href="#" onclick="del(' + n.R_id + ')" name="linkDel" >删除</a></td>');
                sp.push('</tr>');
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        $("input[name=buttReset]").click(function () {
            $("input[name=R_Name]").val('');
            $("input[name=R_Desc]").val('');
            $("input[name=R_SectionCodeList]").removeAttr("checked");
            $("input[name=R_id]").val('0');
        });
        ajax();
        //
        $("input[name=buttsend]").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(role, "#mainForm");
            if (role.R_SectionCodeList == "") {
                alert('请选择角色权限');
                return false;
            }
            $.post("/system/checkRoleName.html", { name: $("#R_Name").val(), id: role.R_id }, function (d) {
                if (d == "0") {
                    $.post("/system/saveRole.html", { role: $.toJSON(role) }, function (dta) {
                        alert('保存成功！');
                        window.parent.frames["rightFrame"].location.reload();
                        ajax();
                    });
                }
                else {
                    alert("角色名重复！");
                }
            });
        });
    });
    function edit(id) {
        $.post("/system/getRolebyid.html?" + (new Date()).getTime(), { res: id }, function (dta) {
            role = $.evalJSON(dta);
            $.fillForm(role, "#mainForm");
        });
        $("input[name=buttsend]").val('修改');
    }
    function del(id) {
        if (confirm("确定删除?")) {
            $.post("/system/deleteRole.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                if (dta == '"n"') {
                    alert("抱歉，该角色已分配账号，不能删除");

                } else {
                    alert("删除成功");
                    $("input[name='buttSeek']").click();
                }
            });
        }
    }
</script>
<body>
    <table cellspacing="0" id="seekForm">
        <tr>
            <th>
                角色管理
            </th>
        </tr>
        <tr>
        <td>
            <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
    </table>
    <table id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">角色列表</caption>
        <tr>
            <th>
                角色名称
            </th>
            <th >
                角色权限列表
            </th>
            <th>
            </th>
            </tr>
        <tbody name="mainlist">
        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table cellspacing="0" id="mainForm">
        <tr>
            <th colspan="3">
                编辑角色
            </th>
        </tr>
         <tr>
            <td>角色名称*</td>
            <td><input id="R_Name" name="R_Name" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>角色说明</td>
            <td><input id="R_Desc" name="R_Desc" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
             <tr>
            <td>角色权限*</td>
            <td>
            <% 
                BIZ.sectionsOper sectionOper=new BIZ.sectionsOper();
                IList plist=(IList)ViewData["parentlist"];
                foreach (Hashtable hs in plist)
                {
                    Response.Write("<div>");
                    //Response.Write("全选<input name=\"allck\" type=\"checkbox\" >");
                    Response.Write("<input type=\"checkbox\" value=\"" + hs["code"] + "\" name=\"R_SectionCodeList\" />");
                    Response.Write(hs["name"]);
                    Response.Write("</br>");
                    int i = 0;
                    foreach (Hashtable h in sectionOper.getListByPId(int.Parse(hs["id"].ToString())))
                    {
                        Response.Write("<input type=\"checkbox\" value=\"" + h["code"] + "\" name=\"R_SectionCodeList\" />");
                        Response.Write(h["name"]);
                        i++;
                        if (i > 7)
                        {
                            Response.Write("<p>"); i = 0;
                        }
                    }
                    Response.Write("</div>");
                    Response.Write("</br>");
                    Response.Write("<div style=\"height:5px\"></div>");
                }
            %>
            <%--<script>
                $(":checkbox[name=allck]").click(function () {
                    if (this.checked) { $("div input:checkbox").attr("checked", "checked"); }
                    else { $("div input:checkbox").removeAttr("checked"); }
                });
            </script>--%>
            </td>            
            <td><input type="hidden" id="R_id" name="R_id" value="0" /> <span class="tsxx"></span></td>
        </tr>
            
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttsend" class="btn1" style="width: 200px" 
                    value="新增" />
            </td>
        </tr>
    </table>
</body>
</html>
